﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using OgilvyOne.DALFactory;
using OgilvyOne.Utility;

namespace OgilvyOne.BLL
{
    /// <summary>
    /// 分页列表标签,循环替换标签内容
    /// <cms:labelpage value="标签定义名" pagesize="分页大小"></cms:labelpage>
    /// </summary>
    class LabelPageLabel : LabelCommonLabel
    {
        private PageLabel pl;

        public LabelPageLabel(CommonModel model)
            : base(model)
        {
            pl = new PageLabel(model);
        }

        private int pagesize;
        public int PageSize
        {
            get { return pagesize; }
            set { pagesize = value; }
        }

        public override string GetLabelLabelHtml()
        {
            pl.MethodName = MethodName;
            pl.Pagesize = pagesize;
            pl.LabelStr = LabelStr;
            
            //sql / node
            XmlDocument doc = GetLabelValueXmlDocument(GetLabelValue());

            pl.LabelNodeStr = doc.SelectSingleNode("//list").Value;
            pl.PageStr = doc.SelectSingleNode("//page").Value;
            if (doc.SelectSingleNode("//pagesize") != null)
            {
                pl.Pagesize = int.Parse(doc.SelectSingleNode("//pagesize").Value);
            }
            if (doc.SelectSingleNode("//method") != null)
            {
                pl.MethodName = doc.SelectSingleNode("//method").Value;
            }


            return pl.GetLabelHtml();
        }
    }
}
